package com.wechat.service.cmds.msg;

import java.util.concurrent.CompletableFuture;

import com.swak.annotation.FluxDepend;
import com.swak.ui.Event;
import com.swak.ui.Events;
import com.wechat.Cons;
import com.wechat.dto.MessageDTO;
import com.wechat.msg.Msg;
import com.wechat.service.MessageServiceAsync;
import com.wechat.service.cmds.CmdHandler;

/**
 * 消息处理：
 * 
 * 1. 存储消息
 * 2. 推送事件
 * 
 * @author 618lf
 */
public abstract class AbstractMsgHandler implements CmdHandler {

	@FluxDepend
	protected MessageServiceAsync messageService;

	/**
	 * 接收到了消息
	 * 
	 * @param command
	 */
	protected CompletableFuture<Void> receive(MessageDTO message, Msg<?> msg) {
		return this.messageService.receive(message, msg)
				.thenAccept(res -> Events.post(Event.of().setKey(Cons.Event_Msg_Recv).setMessage(res)));
	}
}
